<template>
  <el-dialog v-model="props.dialogVisible" title="新增" width="1000" @close="handleClose" class="pdf-dom" ref="fileArea" >
    <free-form ref="addFormRef" formRef="formRef" :rules="props.rules" :model="formModel" :formItemConfig="formItemConfig" label-position="left"
      @parent-event="handleParentEvent" @getformModel="getformModel" />
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import moment from 'moment'
import FreeForm from "@/components/Custom/FreeForm";
import { defineProps } from "vue";
import { addAbnormal,updateAbnormal, addIllegal,updateIllegal,addHandover,updateHandover } from "@/api/government/seeping";
import useUserStore from '@/store/modules/user'

const addFormRef = ref({});
const userStore = useUserStore()
const emit = defineEmits(["handleClose"]);
const methods = ref({  addAbnormal,updateAbnormal, addIllegal,updateIllegal,addHandover,updateHandover  })
const { proxy } = getCurrentInstance();
const props = defineProps({
  dialogVisible: {
    type: Boolean,
  },
  rowDetails: {
    type: Object,
  },
  formItemConfig: {
    type: Array,
  },
  interface: {
    type: String,
  },
  rules: {
    type: Object,
  },
});
const fileArea = ref();

const handleClose = () => {
  emit("handleClose");
};

const data = reactive({
  formModel: props.rowDetails,

});
const { queryParams, formModel, rules } = toRefs(data);


userStore.getInfo().then(res => {
  if (res.code == 200) {
    formModel.value.userId=res.user.userId;
    formModel.value.phoneNum=res.user.phonenumber;
  }

})

const cancel = () => {
  emit("handleClose");
}

/** 提交按钮 */
function submitForm() {
  addFormRef.value?.accountLoginAction();
}


const getformModel = (valid) => {
  if (valid) {
    if (formModel.value.id != null) {
      methods.value['update'+props.interface](formModel.value).then(response => {
        proxy.$modal.msgSuccess("修改成功");
        cancel()
      });
    } else {
      methods.value['add'+props.interface](formModel.value).then(response => {
        proxy.$modal.msgSuccess("新增成功");
        cancel()
      });
    }
  }

}
const handleParentEvent = (data) => {
  // 处理自定义事件的逻辑
  formModel.value[data.name] = data.val;
}

</script>

<style>
.content-cus .el-descriptions__cell {
  border: none !important;
}
.border-top {
  border-top: 1px solid #ebeef5;
}
.padding-none {
  padding: 0 !important;
}
.coumn-cus {
  padding: 8px 11px;
  min-height: 43px;
}
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.text-right {
  text-align: right;
}
</style>
